<template>
  <div class='container'>
    <el-dialog
  title="新增目录"
  :visible.sync="dialogVisible"
  width="30%"
  :before-close="handleClose">

   <div style="display: flex;align-items: center;flex-direction: column;">

   <div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="所属学科" prop="subjectID">
    <el-select v-model="ruleForm.subjectID" style="width: 300px;" placeholder="请选择">
    <el-option
     v-for="(item,index) in arr"
      :key="index"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>

      </el-form-item>
  <el-form-item label="目录名称" prop="directoryName">
    <el-input v-model="ruleForm.directoryName" @keyup.enter.native="handleAdd" style="width: 300px;"></el-input>
  </el-form-item>
  </el-form>
   </div>
   </div>

  <span slot="footer" class="dialog-footer">
    <el-button @click="handleClose">取 消</el-button>
    <el-button type="primary" @click="handleAdd">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import { addList, add } from '@/api/hmmm/directorys'
export default {
  props: {
    dialogVisible: {
      type: Boolean
    }
  },
  data () {
    return {
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }, {
        value: '选项4',
        label: '龙须面'
      }, {
        value: '选项5',
        label: '北京烤鸭'
      }],
      ruleForm: {
        directoryName: '',
        subjectID: ''
      },
      rules: {
        directoryName: [
          { required: true, message: '请输入目录名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      },
      arr: []
    }
  },
  created () {
    this.addList()
  },
  methods: {
    handleClose () {
      this.$emit('update:dialogVisible', false)
    },
    async addList () {
      const data = await addList()
      // console.log(res)
      this.arr = data.data
    },
    // 新增目录
    async handleAdd () {
      this.$emit('update:dialogVisible', false)
      await add(this.ruleForm)
      this.$parent.getlist()
      console.log(this.$parent.form)
      this.ruleForm.directoryName = ''
      this.ruleForm.subjectID = ''
    }
  }
}
</script>

<style scoped lang='less'></style>
